/*=========================== SOFTWARE LICENSE AGREEMENT ===========================
 
    Copyright (c) 2012, Rob Lammert Software
 
    This file is part of SharpLog.
    Author:  Rob Lammert <rob@roblammert.com>

    Foobar is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
  =================================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace com.roblammert.sharplog.Outputs
{
	/// <summary>
	/// CVSLogger is a Logger observer which writes the log messages to a CSV file.
	/// </summary>
	public class CVSLogger : ILogger
	{
		#region Data
		private string mFileName;
		private StreamWriter mLogFile;
		
		/// <summary>
		/// Gets the name of the file.
		/// </summary>
		/// <value>
		/// The name of the file.
		/// </value>
		public string FileName
		{
			get { return mFileName; }
		}
        #endregion

        #region Constructor
		/// <summary>
		/// Initializes a new instance of the <see cref="com.roblammert.log.Outputs.CVSLogger"/> class.
		/// </summary>
		/// <param name='fileName'>
		/// File name.
		/// </param>
		public CVSLogger ( string fileName )
		{
			mFileName = fileName;
		}
        #endregion

        #region Public methods
		/// <summary>
		/// Init this instance.
		/// </summary>
		public void Init()
		{
			mLogFile = new StreamWriter ( mFileName );
			mLogFile.WriteLine ( "\"Date/Time\",\"Method\",\"LineNumber\",\"Log Level\",\"Message\"" );
		}
		
		/// <summary>
		/// Terminate this instance.
		/// </summary>
		public void Terminate()
		{
			mLogFile.Close();
		}
        #endregion

        #region ILogger Members
		/// <summary>
        /// Write Log event to console
        /// </summary>
        /// <param name="eventTime">Date and time that the event took place</param>
        /// <param name="level">Severity Level of the event</param>
        /// <param name="facility">Facility of the event</param>
        /// <param name="method">Method that called the Logger class instance</param>
        /// <param name="logMessage">Message detailing the event</param>
        public void ProcessLogMessage(DateTime date, Logger.Severity level, Logger.Facility facility, String method, String message)
        {
			mLogFile.WriteLine ( "\"" + date.ToString() + "\",\"" + level.ToString() + "\",\"" + facility.ToString() + "\",\"" + method + "\",\"" + message + "\"" );
		}
        #endregion
	}
}

